
import cv2
from head_pose import HeadPose

class FrontFace():
    """
        Detect whether the face is facing the camera.
    """
    #  the front face is |yaw| <= 35 
    front_threshold = 35
    
    def __init__(self):
        super().__init__()

    @staticmethod
    def check(img):
        """
            Get the oriengation of face and check the angle.
            Input:
                img, image contains a face.
            Return:
                is_front, whether the face is facing the camera. 
        """
        # Face orientation detection.
        face_angle = HeadPose.get(img)
        # get the yaw of face.
        face_yaw = face_angle[1]
        # the front face is |yaw| <= 35.
        is_front = False
        if abs(face_yaw) <= 35:
            is_front = True

        return is_front

if __name__ == "__main__":
    
    img = cv2.imread("test/test_3.jpg")
    is_front = FrontFace.check(img)
    print(is_front)